﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using carXapp2;
using System.Threading;
using Phone.Controls;

namespace carXapp2.FuncPages
{
    public partial class Main : PhoneApplicationPage
    {
        
        private string carID;
        private string carIndex;
       

        
        public Main()
        {
           
            InitializeComponent();
           
            this.DataContext = App.ViewModel;
            
        }

        
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            
            NavigationContext.QueryString.TryGetValue("id", out carID);
            NavigationContext.QueryString.TryGetValue("index", out carIndex);

            var selMake = App.ViewModel.SingleCarRecord.CarMake;
            var selModel = App.ViewModel.SingleCarRecord.CarModel;
            var selyear = App.ViewModel.SingleCarRecord.CarYear;
            string delmiter = " ";
            string selected = String.Concat(selyear, delmiter, selMake, delmiter, selModel);
            PageTitle.Text = selected;

            listBox1.SelectedIndex = -1;

            base.OnNavigatedFrom(e);
        }

        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {
            
            NavigationService.Navigate(new Uri("/MiscPages/addEditCar.xaml?index="+carIndex, UriKind.Relative));
        }

      

        private void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            switch (listBox1.SelectedIndex)
            {
                case 0:
                    NavigationService.Navigate(new Uri("/FuncPages/CarStatsInfo.xaml?carID="+carID, UriKind.Relative));
                    break;
                case 1:
                    NavigationService.Navigate(new Uri("/FuncPages/FuelInfo.xaml?carID="+carID, UriKind.Relative));
                    break;
                case 2:
                    NavigationService.Navigate(new Uri("/FuncPages/MaintInfo.xaml?carID=" + carID, UriKind.Relative));
                    break;
                case 3:
                    NavigationService.Navigate(new Uri("/FuncPages/RemiderInfo.xaml?carID=" + carID, UriKind.Relative));
                    break;
            }
        }

       
    }
}